import { ElMessage } from "element-plus";


// 复制文本
export const useCopy = async (text: string): Promise<boolean> => {
    try {
      if (navigator.clipboard) {
        await navigator.clipboard.writeText(text);
        ElMessage.success('复制成功');
        return true;
      } else {
        // Fallback to the old method if clipboard API is not available
        const input = document.createElement('input');
        input.value = text;
        document.body.appendChild(input);
        input.select();
        const result = document.execCommand('Copy');
        document.body.removeChild(input);
        ElMessage.success('复制成功!');

        return result;
      }
    } catch (error) {
      console.error('Failed to copy text: ', error);
      ElMessage.success('复制失败');
      return false;
    }
  };